const toolbarOptions = [
  ["bold", "italic", "underline", "strike"], // 加粗 斜体 下划线 删除线 -----['bold', 'italic', 'underline', 'strike']
  ["blockquote", "code-block"], // 引用  代码块-----['blockquote', 'code-block']
  [{ header: 1 }, { header: 2 }], // 1、2 级标题-----[{ header: 1 }, { header: 2 }]
  [{ list: "ordered" }, { list: "bullet" }], // 有序、无序列表-----[{ list: 'ordered' }, { list: 'bullet' }]
  [{ script: "sub" }, { script: "super" }], // 上标/下标-----[{ script: 'sub' }, { script: 'super' }]
  [{ indent: "-1" }, { indent: "+1" }], // 缩进-----[{ indent: '-1' }, { indent: '+1' }]
  [{ direction: "rtl" }], // 文本方向-----[{'direction': 'rtl'}]
  [{ size: ["small", "middle", "large", "huge"] }], // 字体大小-----[{ size: ['small', false, 'large', 'huge'] }]
  [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题-----[{ header: [1, 2, 3, 4, 5, 6, false] }]
  [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色-----[{ color: [] }, { background: [] }]
  [{ font: [] }], // 字体种类-----[{ font: [] }]
  [{ align: [] }], // 对齐方式-----[{ align: [] }]
  ["clean"], // 清除文本格式-----['clean']
  ["image", "video", "link"], // 链接、图片、视频-----['link', 'image', 'video']
  ["sourceEditor"],
];

const handlers = {
  shadeBox: null,
  sourceEditor: function () {},
  // sourceEditor: function () {
  //   const reg = /\<br\>/g
  //     const container = this.container
  //     const contentBox = container.nextElementSibling.firstChild
  //
  //   if (!this.shadeBox) {
  //     let shadeBox = this.shadeBox = document.createElement('div')
  //     shadeBox.style.cssText = 'position:absolute; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5); cursor:pointer'
  //     container.style.position = 'relative'
  //     shadeBox.addEventListener('click', function () {
  //       this.style.display = 'none'
  //       contentBox.innerHTML = contentBox.innerText.trim()
  //     }, false)
  //     container.appendChild(shadeBox)
  //     let innerHTML = contentBox.innerHTML
  //     innerHTML = innerHTML.replace(reg, '')
  //     contentBox.innerText = innerHTML
  //   } else {
  //     let innerHTML = contentBox.innerHTML
  //     innerHTML = innerHTML.replace(reg, '')
  //     contentBox.innerText = innerHTML
  //     this.shadeBox.style.display = 'block'
  //   }
  // }
};

export default {
  //  富文本编辑器配置
  modules: {
    // 工具栏定义的
    toolbar: {
      container: toolbarOptions,
      handlers,
    },
  },
  // 主题
  theme: "snow",
  placeholder: "请输入内容",
  initButton: function () {
    // 在使用的页面中初始化按钮样式
    const sourceEditorButton = document.querySelector(".ql-sourceEditor");
    sourceEditorButton.style.cssText =
      "width:100px; border:1px solid #ccc; border-radius:5px;";
    sourceEditorButton.innerText = "源码模式";

    // 这里也可以直接引用矢量图
    sourceEditorButton.classList.add("el-icon-edit-outline");
    sourceEditorButton.title = "源码模式";
  },
  register(q) {
    // 注册标签(因为在富文本编辑器中是没有div,table等标签的，需要自己去注册自己需要的标签)
    class div extends q.import("blots/block/embed") {}

    class table extends q.import("blots/block/embed") {}

    class tr extends q.import("blots/block/embed") {}

    class td extends q.import("blots/block/embed") {}

    div.blotName = div.tagName = "div";
    table.blotName = table.tagName = "table";
    tr.blotName = tr.tagName = "tr";
    td.blotName = td.tagName = "td";
    q.register(div);
    q.register(table);
    q.register(tr);
    q.register(td);
  },
};
